package com.jiazixuan.stock.mapper;

import com.jiazixuan.stock.pojo.entity.SysUserRole;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
* @author 17127
* @description 针对表【sys_user_role(用户角色表)】的数据库操作Mapper
* @createDate 2025-08-14 11:17:58
* @Entity com.jiazixuan.stock.pojo.entity.SysUserRole
*/
public interface SysUserRoleMapper {

    int deleteByPrimaryKey(Long id);

    int insert(SysUserRole record);

    int insertSelective(SysUserRole record);

    SysUserRole selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(SysUserRole record);

    int updateByPrimaryKey(SysUserRole record);

    /**
     * 根据用户id获取角色id
     * @param id
     * @return
     */
    List<Long> getRoleIdByUserId(@Param("id") Long id);

    List<String> getOwnRoleIdByUserId(@Param("userId") String userId);

    /**
     * 通过新旧表对比删除多余的角色
     * @param userId
     * @param rolesToDelete
     * @return
     */
    int deleteRoles(@Param("userId") Long userId, @Param("rolesToDelete") List<Long> rolesToDelete);

    /**
     * 通过新旧表对比添加没有的角色
     * @param newRelations
     * @return
     */
    int addRoles(@Param("newRelations") List<SysUserRole> newRelations);

    Long getRolesIdByUser(@Param("userId") String valueOf);
}
